//Add 2 numbers represented by linked lists.
public class LinkedListAdd {

	ListNode addLinkedList(ListNode list1, ListNode list2)
	{

		if(list1==null && list2 == null)
		{
			return list1;
		}

		
		ListNode result;
		ListNode newNode;
		//int countLeft, countRight;

		//int diff = 0;

		if(temp1.getNext()!=null && temp2.getNext()!=null)
		{
			addLinkedList(temp1.getNext(),temp2.getNext());

		}

		else{


			int[] sumArray = add(temp1.getData(), temp2.getData(),carry);
			int sum = sumArray[0];
			int carry = sumArray[1];

			if(temp1 == list1 && temp2 == list2)
			{
				newNode.setData(carry);
				newNode.setNext(result);
				result = newNode;
			}

			else
			{
				newNode.setData(sum);
				newNode.setNext(result);
				result = newNode;
			}


		}
return result;

	}

 	int[] sum(int a, int b, int carry)
 	{
 		int[] result = new int[2];
 		int sumDigits = a+b;
 		if(sumDigits > 9)
 		{
 			result[0] = sumDigits%10;
 			sumDigits=sumDigits/10;
 			result[1] = sumDigits%10; 
 		}

 		return result;
 	}

	
}